package com.bq.gametrade;

import android.app.Application;
import android.content.Intent;
import android.os.Environment;
import android.text.TextUtils;

import com.bq.gametrade.bean.UserInfoDetails;
import com.bq.gametrade.ui.activity.WelcomeActivity;
import com.bq.gametrade.utils.SharedPreferencesUtils;
import com.bq.httplibrary.AsyncHttp;

import java.io.File;


/**
 * @author Feel on 2016/11/24 14:44
 */

public class GameTradeApplication extends Application implements Thread.UncaughtExceptionHandler{


    // 默认存放缓存的路径
    public final static String DEFAULT_SAVE_CACHE_PATH =
            Environment.getExternalStorageDirectory()
                    + File.separator
                    + "/biqi/cache";
    // 默认存放图片的路径

    private static GameTradeApplication instance;

    private UserInfoDetails userInfoDetails;
    public static final String WX_APP_ID = "wx0437f8bd086642b6";
    public static final String WX_APP_SECRET = "9709c35cd60dfa0561b61f9380a52325";




    public UserInfoDetails getUserInfo() {
        return userInfoDetails;
    }

    public void setUserInfo(UserInfoDetails userInfo) {
        this.userInfoDetails = userInfo;
    }

    public boolean isLogin() {
        if (userInfoDetails == null || TextUtils.isEmpty(userInfoDetails.token)) {
            return false;
        }

        return true;
    }




    @Override
    public void onCreate() {
        super.onCreate();
        init();
        initPay();


    }

    private void init(){
        instance = this;
        //初始化网络请求
        AsyncHttp.setContext(this);
        //设置Thread Exception Handler
        Thread.setDefaultUncaughtExceptionHandler(this);
    }



    //遇到异常时退出APP并重新启动
    @Override
    public void uncaughtException(Thread thread, Throwable ex) {
        System.out.println("uncaughtException");
        System.exit(0);
        Intent intent = new Intent(this, WelcomeActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }



    /***
     * 初始化支付
     */
    private void initPay(){
//        iwxapi = WXAPIFactory.createWXAPI(this,WX_APP_ID);
//        iwxapi.registerApp(WX_APP_ID);

    }

    /**
     * 获得当前app运行的AppContext
     *
     * @return
     */
    public static GameTradeApplication getInstance() {
        return instance;
    }

    /***
     * 微信注册
     */


}
